<?php $this->_extends('../_layouts/blank_layout'); ?>
<?php $this->_block('contents'); ?>
<style type="text/css"> 
ul,li{
list-style:none;
font-size:12px;
line-height:20px;
width:400px;
margin:0;
padding-left:6px;
}
.child{
display:none;
}
.nav a{
display:block;
color:#5c84c1;
padding-left:22px;
}
</style> 
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.js"></script>
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.ui.js"></script>
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.mselect.js"></script>
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.multiselect.js"></script>
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.prettyphoto.js"></script>
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/jq.ui.css" rel="stylesheet" />
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/jq.mselect.css" rel="stylesheet" />
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/prettyphoto.css" rel="stylesheet" />

<script language="javascript" type="text/javascript">
var path;
var oldname;
//文件上传
function UploadFile() {
	// 获取文件对象
	var form = new FormData();
	var fileObj=[];
    var file; 
    //取得FileList取得的file集合 
    for(var i = 0 ;i<document.getElementById("file").files.length;i++){ 
        //file对象为用户选择的某一个文件 
        file=document.getElementById("file").files[i]; 
        //此时取出这个文件进行处理，这里只是显示文件名 
         form.append("fileList["+i+"]", file); 
        // fileObj.push(file.name);
    }   
    // 接收上传文件的后台地址 
    var FileController = "<?=url('Online::EbayTemplate/UploadBase')?>";                   
    // FormData 对象
   
    form.append("path", "<?=Q::ini('custom_system/ebay_template_local_dir')?>"+'base/'+ path);                     
    // XMLHttpRequest 对象
    var xhr = new XMLHttpRequest();
    xhr.open("post", FileController, true);
    xhr.send(form);
    xhr.onload = function () {
        alert(xhr.responseText);
        $("#dialog_upload").dialog("close");
        location.reload();
    };
}
//创建文件夹
function CreateCatalogue()
{
	var FileController = "<?=url('Online::EbayTemplate/CreateCatalogue')?>";
    var form = new FormData();
    if(path)
    {
    	 // 增加表单数据
    	form.append("path", "<?=Q::ini('custom_system/ebay_template_local_dir')?>"+'base/'+ path);                       
    }
    else
    {
    	form.append("path", "<?=Q::ini('custom_system/ebay_template_local_dir')?>"+'base/');                  
    }
    form.append("name", $("#name").val());                           // 文件对象
    // XMLHttpRequest 对象
    var xhr = new XMLHttpRequest();
    xhr.open("post", FileController, true);
    xhr.send(form);
    xhr.onload = function () {
        alert(xhr.responseText);
        $("#new_catalogue").dialog("close");
        location.reload();
    };
}
//重命名
function Rename()
{
	var FileController = "<?=url('Online::EbayTemplate/FileRename')?>";
    var form = new FormData();
    if(path)
    {
    	form.append("path", "<?=Q::ini('custom_system/ebay_template_local_dir')?>"+'base/'+ path);                      
    }
    else
    {
    	form.append("path", "<?=Q::ini('custom_system/ebay_template_local_dir')?>"+'base/');                    
    }
    form.append("newname", $("#newname").val());                      // 文件对象
    // XMLHttpRequest 对象
    var xhr = new XMLHttpRequest();
    xhr.open("post", FileController, true);
    xhr.send(form);
    xhr.onload = function () {
        alert(xhr.responseText);
        $("#rename").dialog("close");
        location.reload();
    };
}
//删除
function Delete()
{
	var FileController = "<?=url('Online::EbayTemplate/DeleteBaseFile')?>";
    var form = new FormData();
    if(path)
    {
    	form.append("path", "<?=Q::ini('custom_system/ebay_template_local_dir')?>"+'base/'+ path);                      
    }
    else
    {
    	form.append("path", "<?=Q::ini('custom_system/ebay_template_local_dir')?>"+'base/');                    
    }
    // XMLHttpRequest 对象
    var xhr = new XMLHttpRequest();
    xhr.open("post", FileController, true);
    xhr.send(form);
    xhr.onload = function () {
        alert(xhr.responseText);
        location.reload();
    };
}

function Path(obj)
{
	if (obj.parent().parent().prev().text())
	{
		path = obj.parent().parent().prev().text() + '/' + path;
		Path(obj.parent().parent().prev());
	}
}
//说明 所有的元素以ul li ul li ul li的循环格式嵌套 如果没有下级分类 就用li a结束嵌套
	$(function(){
		$("#new_catalogue").dialog({autoOpen:false,modal:true, height: 180, width: 350});
		$("#dialog_upload").dialog({autoOpen:false,modal:true, height: 180, width: 350});
		$("#rename").dialog({autoOpen:false,modal:true, height: 180, width: 350});
		$("#upload_click").click(function(){
			if(!oldname)
			{
				alert("请选择目录");
				return;
			}
			$("#dialog_upload").dialog("open");
		});
		$("#new_catalogue_click").click(function(){
			$("#name").val("");
			if(!oldname)
			{
				alert("请选择目录");
				return;
			}
			$("#new_catalogue").dialog("open");
		});
		$("#rename_click").click(function(){
			if(!oldname)
			{
				alert("请选择文件或目录");
				return;
			}
			if(oldname=="<?=$base['path']?>")
			{
				alert("该文件夹不允许改名");
				return;
			}
			$("#rename").dialog("open");
			$("#newname").val(oldname);
		});
		$("#delete_click").click(function(){
			if(!oldname)
			{
				alert("请选择文件或目录");
				return;
			}
			if(oldname=="<?=$base['path']?>")
			{
				alert("该文件夹不允许删除");
				return;
			}
			if(confirm("确定要删除"+oldname+"？"))
			{
				Delete();
			}
		});
	$(".nav ul li").children("ul").hide();
	$(".nav").find("li").not(":has(ul)").children("a").css({color:"#333",background:"none"})
	.click(function(){
	//$(this).get(0).location.href="'"+$(this).attr("href")+"'";
	});
	$(".node").click(function() {
	    $(this).css({
	        color: "red"
	    });
	    $(".node").not(this).css({
	        color: "#5c84c1"
	    });
	    oldname = $(this).text();
	    path = oldname;
		Path($(this));
	});
	$(".nav").find("li:has(ul)").children("a").css({
	    background: "url(<?=Q::ini('custom_system/base_url')?>img/close.jpg) no-repeat left top"
	}).click(function() {
	    if ($(this).next("ul").is(":hidden")) {
	        $(this).next("ul").slideDown("slow");
	        if ($(this).parent("li").siblings("li").children("ul").is(":visible")) {
	            $(this).parent("li").siblings("li").find("ul").slideUp("1000");
	            $(this).parent("li").siblings("li:has(ul)").children("a").css({
	                background: "url(<?=Q::ini('custom_system/base_url')?>img/close.jpg) no-repeat left top"
	            }).end().find("li:has(ul)").children("a").css({
	                background: "url(<?=Q::ini('custom_system/base_url')?>img/close.jpg) no-repeat left top"
	            });
	        }
	        $(this).css({
	            background: "url(<?=Q::ini('custom_system/base_url')?>img/open.jpg) no-repeat left top"
	        });
	        return false;
	    } else {
	        $(this).next("ul").slideUp("normal");
	        //不用toggle()的原因是为了在收缩菜单的时候同时也将该菜单的下级菜单以后的所有元素都隐藏
	        $(this).css({
	            background: "url(<?=Q::ini('custom_system/base_url')?>img/close.jpg) no-repeat left top"
	        });
	        $(this).next("ul").children("li").find("ul").fadeOut("normal");
	        $(this).next("ul").find("li:has(ul)").children("a").css({
	            background: "url(<?=Q::ini('custom_system/base_url')?>img/close.jpg) no-repeat left top"
	        });
	        return false;
	    }
	});
	$("#parentnode").click();
	});
</script>
<div style="margin-top:20px">
<table cellspacing="10px">
  <tr>
    <td><a class="base_refresh_icon" title="刷新列表" onclick="location.reload();"></a></td>
    <td><a class="rename_icon" title="重命名" href="javascript:void(0);" id="rename_click"></a></td>
    <td><a class="new_catalogue_icon" title="新建文件夹" href="javascript:void(0);" id="new_catalogue_click"></a></td>
	<td><a class="delete_icon" title="删除" id="delete_click" href="javascript:void(0);"></a></td>
    <td><a class="base_upload_icon" title="上传" href="javascript:void(0);" id="upload_click"></a></td>
  </tr>
</table>
</div>
<br/>
<div class="nav">
	<ul>
	<li>
	<a id="parentnode" class="node"><?=$base['path']?></a>
	<ul class="child">
	<?foreach (Helper_BSS_Normal::getDirlist(Q::ini('custom_system/ebay_template_local_dir').'/base/'.$base['path'] ) as $f):?>
	<li>
	<a class="node"><?=$f?></a>
	<?if (Helper_BSS_Normal::getDirlist(Q::ini('custom_system/ebay_template_local_dir').'/base/'.$base['path'].'/'.$f)):?>
	<ul class="child">
	<?foreach (Helper_BSS_Normal::getDirlist(Q::ini('custom_system/ebay_template_local_dir').'/base/'.$base['path'].'/'.$f ) as $d):?>
	<li><a class="node"><?=$d?></a>
	<?if (Helper_BSS_Normal::getDirlist(Q::ini('custom_system/ebay_template_local_dir').'/base/'.$base['path'].'/'.$f.'/'.$d)):?>
	<ul>
	<?foreach (Helper_BSS_Normal::getDirlist(Q::ini('custom_system/ebay_template_local_dir').'/base/'.$base['path'].'/'.$f.'/'.$d )as $j):?>
	<li><a class="node"><?=$j?></a>
	<?endforeach;?>
	</ul>
	<?endif;?>
	</li>
	<?endforeach;?>
	</ul>
	<?endif;?>
	</li>
	<?endforeach?>
	</ul>
	</li>
	</ul>
 </div>
<div style="margin-top:20px;" id="dialog_upload" title="请选择文件">
	<input type="file" id="file"  name="filesUploaded[]"  multiple="multiple"/>
	<br/>
	<br/>
	<input type="button" onclick="UploadFile()" value="上传" />
</div>
<div style="margin-top:20px;" id="new_catalogue" title="请输入文件夹名">
	<input type="text" id="name" />
	<input type="button" onclick="CreateCatalogue()" value="确定" />
	</div>
<div style="margin-top:20px;" id="rename" title="请输入文件名或文件夹名">
	<input type="text" id="newname" />
	<input type="button" onclick="Rename()" value="确定" />
</div>
<?php $this->_endblock();?>